package com.ruoyi.kanfang.mapstruct;

import com.ruoyi.kanfang.domain.BuildingInfo;
import com.ruoyi.kanfang.dto.BuildingInfoDTO;
import com.ruoyi.kanfang.dto.BuildingInfoDTOF;
import org.mapstruct.*;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author limin
 * @description
 * @date 2024/7/5
 */
@Mapper
public interface BuilderingFactory {

    BuilderingFactory INSTANCE = org.mapstruct.factory.Mappers.getMapper(BuilderingFactory.class);

//    @BeanMapping(ignoreByDefault = true) // 忽略所有未明确映射的属性
    @Mapping(source = "buildingName", target = "buildingName")
    @Mapping(target = "createTm", expression = "java(new java.text.SimpleDateFormat(\"yyyy-MM-dd\").format(buildingInfo.getCreateTm()))")
    @Mapping(source = "source", target = "source",qualifiedByName = "sourceToString")
    BuildingInfoDTO toDTO(BuildingInfo buildingInfo);

    @Named("sourceToString")
    default String sourceToString(Long source){
        return source.equals(1L)?"贝壳":"未知来源";
    }

    @Qualifier
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.CLASS)
    public @interface ConvertBuilding{}

    @ConvertBuilding
    BuildingInfoDTO toDTO2(BuildingInfo buildingInfo);

    @Mapping(target = "dto", qualifiedBy = ConvertBuilding.class)
    BuildingInfoDTOF toDTOF(BuildingInfo buildingInfo);
}
